:root {
    --primary: #2c786c;
    --secondary: #004445;
    --accent: #f8b500;
    --danger: #e74c3c;
    --warning: #f39c12;
    --success: #2ecc71;
    --light: #f8f9fa;
    --dark: #343a40;
    --gray: #6c757d;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #e6f7ff 0%, #f0f8f0 100%);
    color: var(--dark);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    text-align: center;
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 5px;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    background: white;
    padding: 15px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.status-item {
    display: flex;
    align-items: center;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 10px;
}

.status-connected {
    background-color: var(--success);
}

.status-disconnected {
    background-color: var(--danger);
}

.sensor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.sensor-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    overflow: hidden;
}

.sensor-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
}

.sensor-card.alert {
    border-left: 5px solid var(--danger);
}

.sensor-card.warning {
    border-left: 5px solid var(--warning);
}

.sensor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.sensor-icon {
    font-size: 1.8rem;
    color: var(--primary);
}

.sensor-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--dark);
}

.sensor-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--secondary);
    margin-bottom: 5px;
}

.sensor-unit {
    font-size: 0.9rem;
    color: var(--gray);
}

.sensor-range {
    font-size: 0.8rem;
    color: var(--gray);
    margin-top: 10px;
}

.alert-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 10px;
}

.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .charts-container {
        grid-template-columns: 1fr;
    }
}

.chart-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.chart-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--dark);
}

.chart-wrapper {
    height: 250px;
    position: relative;
}

.alerts-panel {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.alert-item {
    padding: 10px 15px;
    border-left: 4px solid var(--danger);
    background: #ffeaea;
    margin-bottom: 10px;
    border-radius: 4px;
}

.alert-item.warning {
    border-left-color: var(--warning);
    background: #fff4e6;
}

.threshold-panel {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.threshold-section {
    margin-bottom: 20px;
}

.threshold-section h4 {
    margin-bottom: 15px;
    color: var(--secondary);
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.threshold-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.threshold-item {
    display: flex;
    flex-direction: column;
}

.threshold-item label {
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--dark);
}

/* 修复输入框重叠问题 */
.threshold-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap; /* 添加换行属性 */
}

.threshold-inputs input {
    flex: 1 1 80px; /* 设置最小宽度 */
    min-width: 80px; /* 确保最小宽度 */
    max-width: 120px; /* 限制最大宽度 */
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.threshold-inputs span {
    color: var(--gray);
}

.control-panel {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.device-controls {
    margin-bottom: 20px;
}

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 15px;
}

.device-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
    transition: all 0.3s ease;
}

.device-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.device-item label {
    font-weight: 600;
    margin-bottom: 10px;
    display: block;
}

.device-switch {
    display: flex;
    gap: 5px;
    align-items: center;
}

.device-switch .btn-sm {
    padding: 5px 12px;
    font-size: 0.8rem;
    transition: all 0.3s ease;
}

/* 设备关闭按钮默认样式 */
.device-off {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    color: #6c757d;
}

/* 设备开启按钮默认样式 */
.device-on {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    color: #6c757d;
}

/* 设备关闭按钮激活状态 */
.device-off.active {
    background-color: #e74c3c;
    border-color: #e74c3c;
    color: white;
    font-weight: 600;
}

/* 设备开启按钮激活状态 */
.device-on.active {
    background-color: #2ecc71;
    border-color: #2ecc71;
    color: white;
    font-weight: 600;
}

/* 按钮激活状态的额外样式类 */
.btn-sm-active {
    padding: 5px 12px !important;
    font-size: 0.8rem !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.device-status {
    margin-left: 10px;
    font-weight: 600;
    color: var(--primary);
}

.device-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    width: 100%; /* 确保占据整个宽度 */
}

/* 风扇滑块容器 - 缩短滑块长度 */
.device-slider .slider-container {
    flex: 1;
    min-width: 0; /* 允许缩小 */
    max-width: 70%; /* 限制最大宽度为70% */
}

.device-slider input {
    width: 100%; /* 占据容器全部宽度 */
    height: 6px;
    border-radius: 3px;
    background: #e9ecef;
    outline: none;
    -webkit-appearance: none;
}

.device-slider input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.device-slider input::-webkit-slider-thumb:hover {
    background: var(--secondary);
    transform: scale(1.1);
}

.device-slider input::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.device-slider input::-moz-range-thumb:hover {
    background: var(--secondary);
    transform: scale(1.1);
}

/* 风扇值显示优化 */
.device-slider .value-display {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--dark);
    min-width: 35px;
    text-align: center;
    flex-shrink: 0; /* 防止被压缩 */
}

/* 响应式设计优化 */
@media (max-width: 768px) {
    .device-slider .slider-container {
        max-width: 65%; /* 移动端进一步缩短 */
    }
}

@media (max-width: 480px) {
    .device-slider .slider-container {
        max-width: 60%; /* 超小屏幕更短 */
    }
}
}

@media (max-width: 768px) {
    .device-switch {
        flex-direction: column;
        gap: 5px;
    }
    
    .device-switch .btn-sm {
        width: 100%;
    }
}

.control-presets {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
    margin: 5px;
}

.btn:hover {
    opacity: 0.9;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

.no-data {
    text-align: center;
    padding: 40px;
    color: var(--gray);
    grid-column: 1 / -1;
}

.last-update {
    text-align: center;
    margin-top: 20px;
    color: var(--gray);
    font-size: 0.9rem;
}

/* 图像显示面板样式 */
.image-panel {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.image-container {
    position: relative;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
}

#cameraImage {
    max-width: 100%;
    max-height: 400px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.no-image {
    text-align: center;
    padding: 40px;
    color: var(--gray);
}

.image-status {
    font-size: 0.9rem;
    font-weight: normal;
    color: var(--gray);
    margin-left: 10px;
}

.image-time {
    font-size: 0.8rem;
    color: var(--gray);
    margin-left: auto;
}

.image-controls {
    display: flex;
    align-items: center;
    margin-top: 10px;
    gap: 10px;
}

/* 图像加载动画 */
.image-loading {
    position: relative;
}

.image-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 模式控制样式 */
.mode-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
}

.mode-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mode-selector label {
    font-weight: 600;
    color: var(--dark);
    margin: 0;
}

.mode-buttons {
    display: flex;
    gap: 5px;
}

.mode-buttons .btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.stream-controls, .capture-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mode-status {
    font-size: 0.9rem;
    color: var(--gray);
    font-style: italic;
}

/* 病虫害检测卡片特殊样式 */
.sensor-card.pest-status {
    border-left: 5px solid #e74c3c;
    background: linear-gradient(135deg, #fff 0%, #fff5f5 100%);
}

.sensor-card.pest-status.alert {
    border-left: 5px solid #e74c3c;
    background: linear-gradient(135deg, #fff 0%, #ffeaea 100%);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* 在警报面板中为病虫害警报添加特殊样式 */
.alert-item.pest-alert {
    border-left: 4px solid #e74c3c;
    background: #ffeaea;
    font-weight: 600;
}

/* 在阈值设置面板中添加病虫害阈值设置 */
.threshold-item.pest-threshold {
    grid-column: 1 / -1;
    border-top: 1px solid #eee;
    padding-top: 15px;
    margin-top: 10px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .status-bar {
        flex-direction: column;
        gap: 10px;
    }
    
    .sensor-grid {
        grid-template-columns: 1fr;
    }
    
    .threshold-grid {
        grid-template-columns: 1fr;
    }
    
    .device-grid {
        grid-template-columns: 1fr;
    }
    
    .control-presets {
        justify-content: center;
    }

    /* 小屏幕下调整阈值输入框布局 */
    .threshold-inputs {
        flex-direction: column;
        align-items: stretch;
    }
    
    .threshold-inputs span {
        display: none; /* 在小屏幕上隐藏波浪线 */
    }
    
    /* 响应式调整模式控制 */
    .mode-controls {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .mode-selector {
        justify-content: center;
    }
    
    .stream-controls, .capture-controls {
        justify-content: center;
    }
    
    /* 图像容器在小屏幕上的调整 */
    .image-container {
        min-height: 250px;
    }
    
    #cameraImage {
        max-height: 300px;
    }
}

/* 模型更新面板样式 */
.model-update-panel {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.model-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 下发区域样式 */
.model-upload-area {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 30px 20px;
    text-align: center;
    background: #f8f9fa;
    transition: all 0.3s ease;
    cursor: pointer;
}

.model-upload-area:hover {
    border-color: var(--primary);
    background: #f0f8ff;
}

.model-upload-area i {
    color: var(--primary);
    margin-bottom: 10px;
}

.model-upload-area p {
    margin: 10px 0 15px;
    color: var(--gray);
}

/* 模型信息样式 */
.model-info {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    border-left: 4px solid var(--primary);
}

.model-details h4 {
    margin-bottom: 10px;
    color: var(--secondary);
}

.model-details p {
    margin: 5px 0;
    font-size: 0.9rem;
}

.model-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* 下发进度样式 */
.upload-progress {
    display: flex;
    align-items: center;
    gap: 15px;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.upload-progress span {
    font-weight: 600;
    color: var(--dark);
    min-width: 40px;
}

/* 下发状态样式 */
.upload-status {
    padding: 10px 15px;
    border-radius: 5px;
    font-size: 0.9rem;
    text-align: center;
}

.upload-status.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.upload-status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.upload-status.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .model-actions {
        flex-direction: column;
    }
    
    .upload-progress {
        flex-direction: column;
        gap: 10px;
    }
    
    .progress-bar {
        width: 100%;
    }
}
